﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;

namespace Pc_Vision.View_Datalayer
{
    public partial class viewProductEdit : System.Web.UI.Page
    {

        public void fn_Cancel(object sender, EventArgs e)
        {

            Response.Redirect("Index.aspx");
        }

        public void fn_EditProduct(object sender, EventArgs e)
        {
            DAOFactorys.DAOproduct daoProduct = new DAOFactorys.DAOproduct();
            Model.Product p = new Model.Product();

            p.articleNumber = tbArticleNumber.Text;
            p.name = tbName.Text;
            p.buyIn = tbBuyIn.Text;
            p.sellPrice = tbSellPrice.Text;
            if (cbInStock.Text == "true") { p.inStock = "1"; }
            else { p.inStock = "0"; }
            p.productDescription = tbProductDescription.Text;
            p.systemType = tbSystemType.Text;
            p.processor = tbProcessor.Text;
            p.memory = tbMemory.Text;
            p.storage = tbStorage.Text;
            p.opticalDisk = tbOpticalDisk.Text;
            p.display = tbDisplay.Text;
            p.videoCard = tbVideoCard.Text;
            p.networkCard = tbNetworkCard.Text;
            p.battery = tbBattery.Text;
            p.dimension = tbDimension.Text;
            p.weight = tbWeight.Text;
            p.warranty = tbWarranty.Text;
            p.actionPrice = tbActionPrice.Text;
            p.categorieID = ddlCategorie.SelectedIndex.ToString();

            daoProduct.UpdateProduct(p);
        }
        public void fn_SearchProduct(object sender, EventArgs e)
        {
            DAOFactorys.DAOproduct daoProduct = new DAOFactorys.DAOproduct();
            ArrayList arr = daoProduct.GetAllProducts();
            string searchVal = tbArticleNumber.Text;
            foreach (Model.Product obj in arr)
            {
                if (obj.articleNumber == searchVal)
                {
                    tbName.Text = obj.name;
                    tbBuyIn.Text = obj.buyIn;
                    tbSellPrice.Text = obj.sellPrice;
                    if (obj.inStock == "True")
                    {
                        cbInStock.Checked = true;
                    }
                    else if (obj.inStock == "False")
                    {
                        cbInStock.Checked = false;
                    }
                    tbProductDescription.Text = obj.productDescription;
                    tbSystemType.Text = obj.systemType;
                    tbProcessor.Text = obj.processor;
                    tbMemory.Text = obj.memory;
                    tbStorage.Text = obj.storage;
                    tbOpticalDisk.Text = obj.opticalDisk;
                    tbDisplay.Text = obj.display;
                    tbVideoCard.Text = obj.videoCard;
                    tbNetworkCard.Text = obj.networkCard;
                    tbBattery.Text = obj.battery;
                    tbBattery.Text = obj.battery;
                    tbDimension.Text = obj.dimension;
                    tbWeight.Text = obj.weight;
                    tbWarranty.Text = obj.warranty;
                    tbActionPrice.Text = obj.actionPrice;
                    ddlCategorie.SelectedItem.Text = obj.categorieID;
                    ddlRating.SelectedItem.Text = obj.rating;

                }
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {

        }
    }
}